//
//  MPMainController.swift
//  MPSinaWeibo
//
//  Created by DaVinci on 16/4/6.
//  Copyright © 2016年 DaVinci. All rights reserved.
//

import UIKit

class MPMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
       
        let mainTabbar = MPTabbar()
        
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnClick", forControlEvents: .TouchUpInside)
        
        setValue(mainTabbar, forKey: "tabBar")
        
        
        
        addChildControllers()
    }
    
   @objc private func plusBtnClick(){
    
    
    
    }

    private func addChildControllers() {
    
       let discovery = MPDiscoveryController()
       let home = MPHomeController()
       let message = MPMessageController()
       let profile = MPProfileController()
        
        addchildController(home, imageName: "tabbar_home",title: "首页")
        addchildController(message, imageName: "tabbar_message_center",title: "消息")

        addchildController(discovery, imageName: "tabbar_discover",title: "发现")
        addchildController(profile, imageName: "tabbar_profile",title: "我")

    }
    
    func addchildController(vc: UIViewController,imageName: String,title: String) {
    
//       vc.tabBarItem.title = title
//       vc.navigationItem.title = title
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)

        
        
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        
//        self.tabBar.tintColor = UIColor.orangeColor()
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState:.Selected)
        
        let nav = MPBaseNavController(rootViewController: vc)

        
        addChildViewController(nav)
    
    }
}
